# -*- coding: utf-8 -*-
from PyQt5 import QtWidgets
from gui.data_analysis.hist_condition_setting import Ui_Dialog
from PyQt5.QtGui import QIcon, QPixmap
from PyQt5.QtCore import pyqtSignal, pyqtSlot
from PyQt5.QtWidgets import QDialog, QMessageBox
from utils.color_util import color
from utils.log_util import loggings as logger


class HistConditionWindow(QtWidgets.QDialog, Ui_Dialog):
    dialogSignal = pyqtSignal(object, object,object)
    selectedSignal = pyqtSignal(object)

    def __init__(self):
        super().__init__()
        self.setupUi(self)
        icon = QIcon()
        icon.addPixmap(
            QPixmap("icons/logo.ico"),
            QIcon.Normal,
            QIcon.Off)
        self.setWindowIcon(icon)
        self.cbb_data_name.currentIndexChanged.connect(self.select_index)

    def select_index(self, idx):
        if idx:
            self.selectedSignal.emit(idx)

    def set_para_2_widget(self, test_para):
        self.cbb_para.clear()
        self.cbb_para.addItems(test_para)

    def set_data_list_2_widget(self, data_list):
        self.cbb_selected_name.clear()
        self.cbb_selected_name.addItems(data_list)


    @pyqtSlot()
    def on_btnEnsure_clicked(self):
        data_type = self.cbb_data_name.currentText().strip()
        test_para = self.cbb_para.currentText().strip()
        data_list = self.cbb_selected_name.checkedItems

        if data_type and test_para and data_list:
            self.dialogSignal.emit(data_type,test_para, data_list)
            # self.close()
        else:
            self.show_notification("提示","请选择查询项")

    def show_notification(self, title, content):
        QMessageBox.information(self, title, content, QMessageBox.Yes, QMessageBox.Yes)

    @pyqtSlot()
    def on_btnCancel_clicked(self):
        self.close()
